package com.zretc.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.zretc.dao.AccountDao;
import com.zretc.entity.Account;
import com.zretc.util.DBUtil;

public class AccountDaoImpl implements AccountDao{

	@Override
	public int insert(Account account) {
		
		return DBUtil.doUpdate("insert into account(account_id,account_tel,account_pwd,account_picture,vip_status) values(?,?,?,?,?)", account.getAccountId(),account.getAccountTel(),account.getAccountPwd(),account.getAccountPicture(),account.getVipStatus());
	}

	@Override
	public Account findByAccountTel(String accountTel) {
		Account account = null;
		ResultSet doQuery = DBUtil.doQuery("select account_id,account_pwd,vip_status,account_picture from account where account_tel = ?",accountTel);
		try {
		while (doQuery.next()) {
			Integer accountId = doQuery.getInt("account_id");
			String accountPwd = doQuery.getString("account_pwd");
			Integer vipStatus = doQuery.getInt("vip_status");
			String accountPicture = doQuery.getString("account_picture");
			account = new Account(accountId, accountPwd, vipStatus, accountPicture);
		    }
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return account;
	}

	@Override
	public Account findByAccountTelAndPwd(String accountTel, String accountPwd) {
		Account account = null;
		ResultSet doQuery = DBUtil.doQuery("select account_id,account_tel,account_pwd,vip_status,account_picture from account where account_tel = ? and account_pwd = ?"
				 ,accountTel,accountPwd);
		try {
			while (doQuery.next()) {
				Integer accountId = doQuery.getInt("account_id");
				Integer vipStatus = doQuery.getInt("vip_status");
				String accountPicture = doQuery.getString("account_picture");
				account = new Account(accountId, accountTel, accountPwd, vipStatus, accountPicture);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return account;
		
		
	}

}
